<template>
	<view class="content">
		<view class="head">
			<view class="head-text" @tap="openmodify(0, 'center')">修改员工信息</view>
		</view>

		<!-- 员工邀约列表 -->
		<staffInvList :invite_list_data="invite_list_data" :length="invite_list_data.length" :staff_name="staff_info_data.name" :scrollH="scrollH" :status="status" />
		 
		<view class="top" :style="{'display':(flag===true? 'block':'none')}">
			<uni-icons class="topc" type="arrowthinup" size="30" @click="top"></uni-icons>
		</view>

		<openAlert BgColor="rgba(0,0,0,0.7)" ref="openAlertmodify" :AlertClass="AlertClass" :AlertPosition="AlertPosition"  closeBtn>
			<view class="modify">
				<view class="modify-title">修改信息</view>
				<view class="modify-info">
					<view>姓名:
						<input :placeholder="staff_info_data.name" focus type="text" class="modify-input" v-model="staff.username" />
					</view>
					<view>电话:
						<input :placeholder="staff_info_data.tel" type="number" maxlength="11" class="modify-input" v-model="staff.userphone" />
					</view>
					<view><button @click="queren()" class="modify-but">确&nbsp;&nbsp;&nbsp;&nbsp;认</button></view>
					<view><button @click="quxiao()">取&nbsp;&nbsp;&nbsp;&nbsp;消</button></view>
				</view>
			</view>
		</openAlert>

	</view>
</template>

<script>
	import uQRCode from '../../common/uqrcode.js'
	import uniIcons from '../../components/common/uni-icons/uni-icons.vue'

	export default {
		components: {
			uniIcons,
		},
		data() {
			return {
				scrollH: 100,
				AlertClass: 0,
				AlertPosition: '',
				staff_info_data: {},
				staff_id: '',
				staff: {
					username: '',
					userphone: '',
				},
				list: {},
				invite_list_data: [],
				page: 1,
				status: 'nomore',
				flag: false,
			};
		},
		onLoad(e) {
			console.log(e)
			this.staff_id = e.staff_id
			this.activity_id = e.activity_id
			this.$comm.appLogin(user_info=>{
				this.staff_info()
				this.invite_list()
				this.get_scrollH()
			})
		},
		onPullDownRefresh() {
			this.loaddata()
		},
		onReachBottom() {
			// this.invite_list()
		},
		methods: {
			//修改信息
			queren(id) {
				if (this.staff.username == '') {
					uni.showToast({
						title: '员工姓名不能为空',
						icon: 'none'
					})
					return false
				}
				if (this.staff.userphone == '') {
					uni.showToast({
						title: '员工电话不能为空',
						icon: 'none'
					})
					return false
				} else {
					let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
					if (!myreg.test(this.staff.userphone)) {
						uni.showToast({
							title: '员工电话不合法',
							icon: 'none'
						});
						return false;
					}
				}
				this.$comm.request({
					url: 'api/staff_update',
					method: 'POST',
					data: {
						activity_id: this.activity_id,
						staff_id: this.staff_id,
						name: this.staff.username,
						tel: this.staff.userphone,
					},
					success: res => {
						var res = res.data
						console.log(res)
						console.log(res.code)
						if (res.code == 200) {
							uni.showToast({
								title: res.msg
							})
							this.$refs.openAlertmodify.Close();
							this.staff_info()
							return
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					}
				})
			},

			//获取员工信息
			staff_info(id) {
				// console.log(this.$comm.app_config.share_url)
				this.$comm.request({
					url: 'api/staff_info?staff_id=' + this.staff_id + '&activity_id=' + this.activity_id,
					method: 'GET',
					success: res => {
						console.log(res);
						this.staff_info_data = res.data.result;
						this.staff.username = res.data.result.name;
						this.staff.userphone = res.data.result.tel;

					}
				});
			},

			//获取员工邀约列表
			invite_list() {
				// if (this.status == 'nomore') {
				// 	return
				// }
				this.$comm.request({
					url: 'api/factory_invite_list?staff_id=' + this.staff_id + '&activity_id=' + this.activity_id,
					method: 'GET',
					data: {
						// page: this.page++
					},
					success: res => {
						this.invite_list_data = res.data.result
						console.log(this.invite_list_data, '员工邀约列表')
						let list = res.data.result
						if (list.length < 10) {
							this.status = 'nomore'
						}
					}
				})
			},

			loaddata() {
				this.page = 1
				this.status = 'more'
				this.invite_list_data = []
				this.invite_list()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},

			get_scrollH() {
				//获取可视区域高度
				uni.getSystemInfo({
					success: (res) => {
						this.scrollH = res.windowHeight - uni.upx2px(268)
						// console.log(res.windowHeight, '可视区域高度',this.scrollH)
					}
				})
			},

			//打开修改信息
			openmodify(Class, Position) {
				this.$nextTick(function() {
					this.AlertClass = Class;
					this.AlertPosition = Position;
					this.$nextTick(function() {
						this.$refs.openAlertmodify.Show();
					});
				});
			},

			//修改信息页面取消按钮
			quxiao() {
				this.$refs.openAlertmodify.Close();
			},

			//回到顶部
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
		},
		onPageScroll(e) { //根据距离顶部距离是否显示回到顶部按钮
			if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
				this.flag = true
			} else { //当距离小于600时显示回到顶部按钮
				this.flag = false
			}
		},
	};
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		background-color: #f1f1f1;
		font-size: 30rpx;
	}

	.head {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 30rpx;
	}

	image {
		width: 100rpx;
		height: 100rpx;
		margin-left: 20rpx;
		// background-color: #000;
	}

	.head-text {
		color: #ffffff;
		line-height: 2.5;
		background-color: #475dfc;
		text-align: center;
		border-radius: 50rpx;
		width: 400rpx;
	}

	.invitetitle {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 60rpx;
		margin-top: 30rpx;
	}

	.invitetitle-em {
		height: 35rpx;
		width: 10rpx;
		background-color: #475dfc;
		border-radius: 50rpx;
	}

	.invitetitle-text {
		margin-left: 10rpx;
	}

	.invitetabtitle {
		margin: 20rpx 0rpx 10rpx 20rpx;
		display: flex;
		justify-content: space-around;

		view {
			width: 25%;
			text-align: center;
		}
	}

	.tabdivide {
		background-color: #d9d9d9;
		height: 1rpx;
		width: 100%;
		margin-top: 5rpx;
	}

	.foot {
		text-align: center;
		margin-top: 60rpx;
		margin-bottom: 20rpx;
	}

	.tabstyle {
		display: flex;
		// // justify-content: space-around;
		margin: 20rpx 15rpx 0 20rpx;
		align-items: center;
	}

	.tabtext {
		width: 25%;
		// background-color: #9000FF;
		text-align: center;
	}

	.call {
		height: 35rpx;
		width: 35rpx;
	}

	.tabmark {
		background-color: #475dfc;
		margin-left: 20rpx;
		margin-right: 20rpx;
		color: #ffffff;
		border-radius: 50rpx;
	}

	@mixin but {
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		background-color: #475dfc;
		color: #ffffff;
	}

	.modify-but {
		@include but;
	}

	.share-but {
		@include but;
	}

	.share {
		width: 650rpx;
		background-color: #FFF;
		padding: 50rpx;
		border-radius: 12rpx;
	}

	.canvas {
		width: 550rpx;
		height: 550rpx;
	}


	.modify-input {
		background-color: rgba(0, 0, 0, 0.2);
		color: #000000;
		height: 70rpx;
		margin-top: 5rpx;
		padding-left: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 12rpx;
	}

	.foot {
		text-align: center;
		margin-top: 60rpx;
		margin-bottom: 20rpx;
	}

	.modify {
		width: 550rpx;
		background-color: none;
		background: #fff;
		padding: 50rpx;
		border-radius: 12rpx;
	}

	.modify-title {
		text-align: center;
		font-size: 45rpx;
		margin-bottom: 40rpx;
	}

	.modify-info {
		display: flex;
		flex-direction: column;
		color: #000000;
		font-size: 30rpx;

		view {
			// margin-bottom: 40rpx;
		}
	}

	@mixin but {
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		background-color: #475dfc;
		color: #ffffff;
	}

	.modify-but {
		@include but;
	}

	.top {
		position: relative;
		display: none;
		/* 先将元素隐藏 */
	}

	.topc {
		position: fixed;
		right: 0;
		// background: #F0F0F0;
		bottom: 50rpx;
		right: 50rpx;
		background-color: #FFF;
		border: solid 2rpx #475dfc;
		border-radius: 100rpx;
		height: 80rpx;
		width: 80rpx;
		line-height: 80rpx;
	}
</style>
